//
//  StyleSelecteView.swift
//  ShiZhe
//
//  Created by 陈卿伟 on 16/10/8.
//  Copyright © 2016年 陈卿伟. All rights reserved.
//

import UIKit

class StyleSelecteView: UIView {
    var boardView:UIView!//灰色底部
    init(frame: CGRect,selecteItem:Int) {
        boardView = UIView()
        super.init(frame: frame)
        self.jugdeNeedIcon(selecteItem)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //创建中间的承载框
    func createBoard(){
        boardView.frame = CGRectMake(0, 24, 235*SCALEW, 38*SCALEH)
        boardView.backgroundColor = BaseFunc.createCustomColor(205, b: 205, g: 205, a: 1)
        boardView.layer.cornerRadius = 6
        self.addSubview(boardView)
    }
    
    //判断要呈现的icon有哪些
    func jugdeNeedIcon(selecteItem:Int){
        var nosIconName:Array<String>//没选择的时候的icon名
        var sIconName:Array<String>//选择了之后的icon名
        switch selecteItem {
        case 0:
            nosIconName = ["B1","s1","i1","H11","H21","H31","H41"]
            sIconName = ["B2","s2","i2","H12","H22","H32","H42"]
            createBoard()
            createSelecteIcon(nosIconName, iconName2: sIconName, iconWidth: 31)
        case 1:
            nosIconName = ["takePhotoIcon","albumicon","LinkIcon","splitLineIcon"]
            sIconName = ["takePhotoIcon","albumicon","LinkIcon","splitLineIcon"]
            self.createBoard()
            createSelecteIcon(nosIconName, iconName2: sIconName, iconWidth: 50)
        case 2:
            break
        case 3:
            break
        case 4:
            nosIconName = ["numSortIcon1","dotSortIcon1","rightindentIcon","leftIndentIcon"]
            sIconName = ["numSortIcon2","dotSortIcon2","rightindentIcon","leftIndentIcon"]
            self.createBoard()
            createSelecteIcon(nosIconName, iconName2: sIconName, iconWidth: 50)
        default:
            break
        }
    }
    
    //创建呈现的icon
    func createSelecteIcon(iconName1:Array<String>,iconName2:Array<String>,iconWidth:CGFloat){
        let allWidth = CGFloat(iconName1.count)*iconWidth*SCALEW
        let firstWidth = (235*SCALEW-allWidth)/2
        for i in 0..<iconName1.count{
            let iconButton = UIButton(frame: CGRectMake(firstWidth+iconWidth*CGFloat(i)*SCALEW,2*SCALEH,iconWidth*SCALEW,34*SCALEH))
            iconButton.setImage(UIImage(named: iconName1[i]), forState: .Normal)
            iconButton.setImage(UIImage(named: iconName2[i]), forState: .Selected)
            iconButton.tag = 8120+i
            boardView.addSubview(iconButton)
        }
    }
}









